using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace EndNoteHelper.ReferenceEntities
{
    public class FileOperation
    {
        public static IList<string> GetFileLines(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new FileNotFoundException(); 
            }

            FileStream fs = new FileStream(fileFullName, FileMode.Open);
            StreamReader sm = new StreamReader(fs);

            IList<string> fileContentLines = new List<string>();

            while (!sm.EndOfStream)
            {
                fileContentLines.Add(sm.ReadLine());
            }
            sm.Close();
            fs.Close();

            return fileContentLines;
        }

        public  static string GetFileContent(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new FileNotFoundException();
            }

            FileStream fs = new FileStream(fileFullName, FileMode.Open);
            StreamReader sm = new StreamReader(fs);

            string fileContent = sm.ReadToEnd();

            sm.Close();
            fs.Close();

            return fileContent;
        }

        public static void WriteStringToFile(string fileFullName, string fileContent)
        {
            try
            {
                Stream myStream = new FileStream(fileFullName, FileMode.Create);
                StreamWriter sw = new StreamWriter(myStream, Encoding.UTF8);
                sw.Write(fileContent);
                sw.Close();
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
    }
}